//
//  MyMapViewController.m
//  markmap
//
//  Created by 甘世清 on 2024/3/23.
//

#import "MyMapViewController.h"
#import "MyMapAllViewController.h"
#import "MyMapListViewController.h"
#import "AddAnnViewController.h"
@interface MyMapViewController ()
@property (nonatomic , strong) MyMapAllViewController * homeVC;
@property (nonatomic , strong) MyMapListViewController * listVC;
@property (nonatomic , strong) HeaderView * addButton;
@end

@implementation MyMapViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self SQ_uiViewForSelf];
    UIImageView * bg = [[UIImageView alloc]init];
    bg.image = SQGetImage(@"listbg");
    bg.contentMode = UIViewContentModeScaleAspectFill;
    [self.tabContentView addSubview:bg];
    [bg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.tabContentView);
    }];
    [self.tabContentView sendSubviewToBack:bg];
    
    SQCustomButton * add = [[SQCustomButton alloc]initType:SQCustomButtonTopImageType imageSize:CGSizeMake(20, 20) midmargin:0];
    add.image = SQGetImage(@"返回键-01");
    [self.view addSubview:add];
    [add mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.tabBar);
        make.size.mas_equalTo(50);
        make.left.equalTo(self.view).offset(4);
    }];
    WS(weakSelf);
    [add setTouchBlock:^(SQCustomButton * _Nonnull button) {
        [weakSelf.navigationController popViewControllerAnimated:YES];
    }];
    
    [self.view addSubview:self.addButton];
    [self.addButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(SCREEN_WIDETH-60);
        make.centerX.equalTo(self.view);
        make.bottom.equalTo(self.view.mas_bottom).offset(-FootHeight-10);
        make.height.mas_equalTo(50);
    }];
}
-(void)SQ_uiViewForSelf{
    self.tabBar.indicatorColor = SQColor(@"#E133FF");
    self.tabBar.indicatorCornerRadius = 1;
    self.tabContentView.loadViewOfChildContollerWhileAppear = YES;
    self.tabBar.backgroundColor = UIColor.clearColor;
    self.tabBar.itemTitleSelectedFont = FONT_MEDIUM(20);
    self.tabBar.itemTitleFont = FONT_MEDIUM(20);
    self.tabBar.itemTitleColor = SQColor(@"#AAAAAA");
    self.tabBar.itemTitleSelectedColor = UIColor.whiteColor;
    [self setTabBarFrame:CGRectMake(100, TopHeight-40, SCREEN_WIDETH-200, 40)
        contentViewFrame:CGRectMake(0, 0, SCREEN_WIDETH, SCREEN_HEIGHT)];
    self.viewControllers = [NSMutableArray arrayWithObjects:self.listVC, self.homeVC,nil];
    [self.tabBar setItemContentHorizontalCenterAndMarginTop:10 spacing:0];
    [self.tabContentView setContentScrollEnabled:YES tapSwitchAnimated:YES];
    self.tabContentView.backgroundColor = UIColor.clearColor;
    [self.tabBar setIndicatorWidth:24 marginTop:34 marginBottom:2 tapSwitchAnimated:YES];
    
    
}
-(void)SQ_addAnntionForMap{
    AddAnnViewController * vc = [[AddAnnViewController alloc]init];
    vc.modalPresentationStyle = UIModalPresentationFullScreen;
    [self presentViewController:vc animated:YES completion:nil];
}

- (MyMapAllViewController *)homeVC{
    if (!_homeVC) {
        _homeVC = [[MyMapAllViewController alloc]init];
        _homeVC.yp_tabItemTitle = SQNSLocalString(@"地图");
    }
    return _homeVC;
}
- (MyMapListViewController *)listVC{
    if (!_listVC) {
        _listVC = [[MyMapListViewController alloc]init];
        _listVC.yp_tabItemTitle = SQNSLocalString(@"列表");
    }
    return _listVC;
}

- (HeaderView *)addButton{
    if (!_addButton) {
        _addButton = [[HeaderView alloc]init];
        _addButton.image = @"矩形";
        _addButton.colorString = @"#FFFFFF";
        [_addButton.btn addTarget:self action:@selector(SQ_addAnntionForMap) forControlEvents:UIControlEventTouchUpInside];
//        _addButton.layer.cornerRadius = 6;
        _addButton.layer.masksToBounds = YES;
        _addButton.text = SQNSLocalString(@"新增觅点");
        _addButton.font = FONT_MEDIUM(18);
    }
    return _addButton;
}
@end
